<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>医院管理系统 - 注册</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 2rem 0;
        }
        .register-container {
            background: white;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }
        .register-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 2rem;
            text-align: center;
        }
        .register-form {
            padding: 2rem;
        }
        .form-control {
            border-radius: 10px;
            border: 2px solid #e9ecef;
            padding: 12px 15px;
        }
        .form-control:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
        }
        .btn-register {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            border-radius: 10px;
            padding: 12px;
            font-weight: 600;
            transition: transform 0.2s;
        }
        .btn-register:hover {
            transform: translateY(-2px);
        }
        .role-selector {
            display: flex;
            gap: 1rem;
            margin-bottom: 2rem;
        }
        .role-card {
            flex: 1;
            border: 2px solid #e9ecef;
            border-radius: 10px;
            padding: 1.5rem;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s;
        }
        .role-card:hover {
            border-color: #667eea;
            transform: translateY(-2px);
        }
        .role-card.active {
            border-color: #667eea;
            background: rgba(102, 126, 234, 0.1);
        }
        .login-link {
            color: #667eea;
            text-decoration: none;
        }
        .login-link:hover {
            color: #764ba2;
        }
        .doctor-form, .patient-form {
            display: none;
        }
        .doctor-form.show, .patient-form.show {
            display: block;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8 col-lg-6">
                <div class="register-container">
                    <div class="register-header">
                        <i class="fas fa-user-plus fa-3x mb-3"></i>
                        <h3>用户注册</h3>
                        <p class="mb-0">请选择注册类型并填写信息</p>
                    </div>
                    <div class="register-form">
                        <!-- 角色选择 -->
                        <div class="role-selector">
                            <div class="role-card" data-role="doctor">
                                <i class="fas fa-user-md fa-2x mb-2 text-primary"></i>
                                <h5>医生注册</h5>
                                <p class="text-muted small">注册医生账户</p>
                            </div>
                            <div class="role-card" data-role="patient">
                                <i class="fas fa-user fa-2x mb-2 text-success"></i>
                                <h5>患者注册</h5>
                                <p class="text-muted small">注册患者账户</p>
                            </div>
                        </div>

                        <!-- 医生注册表单 -->
                        <form id="doctorForm" class="doctor-form">
                            <h5 class="mb-3"><i class="fas fa-user-md me-2"></i>医生信息</h5>
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label for="doctorName" class="form-label">姓名 *</label>
                                    <input type="text" class="form-control" id="doctorName" name="name" required>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label for="doctorSex" class="form-label">性别 *</label>
                                    <select class="form-control" id="doctorSex" name="sex" required>
                                        <option value="">请选择</option>
                                        <option value="男">男</option>
                                        <option value="女">女</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label for="doctorAge" class="form-label">年龄 *</label>
                                    <input type="number" class="form-control" id="doctorAge" name="age" required>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label for="doctorTitle" class="form-label">职称 *</label>
                                    <input type="text" class="form-control" id="doctorTitle" name="title" required>
                                </div>
                            </div>
                            <div class="mb-3">
                                <label for="doctorMajor" class="form-label">专业 *</label>
                                <input type="text" class="form-control" id="doctorMajor" name="major" required>
                            </div>
                            <div class="mb-3">
                                <label for="doctorInfo" class="form-label">医生简介 *</label>
                                <textarea class="form-control" id="doctorInfo" name="info" rows="3" required></textarea>
                            </div>
                            <div class="mb-3">
                                <label for="doctorDepName" class="form-label">所属科室 *</label>
                                <input type="text" class="form-control" id="doctorDepName" name="depName" required>
                            </div>
                            <div class="mb-3">
                                <label for="doctorPw" class="form-label">初始密码 *</label>
                                <input type="password" class="form-control" id="doctorPw" name="pw" required>
                            </div>
                            <div class="d-grid">
                                <button type="submit" class="btn btn-primary btn-register">
                                    <i class="fas fa-user-plus me-2"></i>注册医生账户
                                </button>
                            </div>
                        </form>

                        <!-- 患者注册表单 -->
                        <form id="patientForm" class="patient-form">
                            <h5 class="mb-3"><i class="fas fa-user me-2"></i>患者信息</h5>
                            <div class="mb-3">
                                <label for="patientName" class="form-label">姓名 *</label>
                                <input type="text" class="form-control" id="patientName" name="name" required>
                            </div>
                            <div class="mb-3">
                                <label for="patientCardId" class="form-label">身份证号 *</label>
                                <input type="text" class="form-control" id="patientCardId" name="cardId" required>
                            </div>
                            <div class="mb-3">
                                <label for="patientPhone" class="form-label">手机号 *</label>
                                <input type="tel" class="form-control" id="patientPhone" name="phone" required>
                            </div>
                            <div class="mb-3">
                                <label for="patientPw" class="form-label">密码 *</label>
                                <input type="password" class="form-control" id="patientPw" name="pw" required>
                            </div>
                            <div class="d-grid">
                                <button type="submit" class="btn btn-success btn-register">
                                    <i class="fas fa-user-plus me-2"></i>注册患者账户
                                </button>
                            </div>
                        </form>

                        <div class="text-center mt-3">
                            <p class="mb-0">已有账户？ 
                                <a href="/login" class="login-link">立即登录</a>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="/js/bootstrap.bundle.min.js"></script>
    <script src="/js/axios.min.js"></script>
    <script>
        // 配置axios基础URL
        axios.defaults.baseURL = '';
        
        // 角色选择
        const roleCards = document.querySelectorAll('.role-card');
        const doctorForm = document.getElementById('doctorForm');
        const patientForm = document.getElementById('patientForm');
        
        roleCards.forEach(card => {
            card.addEventListener('click', function() {
                // 移除所有active类
                roleCards.forEach(c => c.classList.remove('active'));
                // 添加active类到当前卡片
                this.classList.add('active');
                
                const role = this.dataset.role;
                if (role === 'doctor') {
                    doctorForm.classList.add('show');
                    patientForm.classList.remove('show');
                } else if (role === 'patient') {
                    patientForm.classList.add('show');
                    doctorForm.classList.remove('show');
                }
            });
        });

        // 医生注册表单提交
        document.getElementById('doctorForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const data = Object.fromEntries(formData);
            data.sex = data.sex;
            data.age = parseInt(data.age);
            data.state = 1; // 正常状态
            
            try {
                const response = await axios.post('/doctor/signup', data);
                
                if (response.data.code === 200) {
                    alert('医生注册成功！');
                    window.location.href = '/login';
                } else {
                    alert('注册失败：' + response.data.msg);
                }
            } catch (error) {
                console.error('注册错误:', error);
                alert('注册失败，请检查网络连接');
            }
        });

        // 患者注册表单提交
        document.getElementById('patientForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const data = Object.fromEntries(formData);
            data.state = 1; // 正常状态
            
            try {
                const response = await axios.post('/patient/signup', data);
                
                if (response.data.code === 200) {
                    alert('患者注册成功！');
                    window.location.href = '/login';
                } else {
                    alert('注册失败：' + response.data.msg);
                }
            } catch (error) {
                console.error('注册错误:', error);
                alert('注册失败，请检查网络连接');
            }
        });

        // 身份证号验证
        document.getElementById('patientCardId').addEventListener('input', function(e) {
            const value = e.target.value;
            if (value.length > 18) {
                e.target.value = value.slice(0, 18);
            }
        });

        // 手机号验证
        document.getElementById('patientPhone').addEventListener('input', function(e) {
            const value = e.target.value;
            if (value.length > 11) {
                e.target.value = value.slice(0, 11);
            }
        });
    </script>
</body>
</html>
